package firm_manage

import (
	"backend/models"
	"backend/pkg/app"
	"backend/pkg/e"
	"github.com/gin-gonic/gin"
	"github.com/unknwon/com"
)

func GetALlOrder(c *gin.Context) { //获取所有的订单信息
	page := -1
	if arg := c.Query("page"); arg != "" {
		page = com.StrTo(arg).MustInt()
	}
	limit := -1
	if arg := c.Query("limit"); arg != "" {
		limit = com.StrTo(arg).MustInt()
	}
	searchText := ""
	if arg := c.Query("searchText"); arg != "" {
		searchText = arg
	}
	GoodParam := map[string]interface{}{
		"page":       page,
		"limit":      limit,
		"searchText": searchText,
	}
	err, info, total := models.GetOrder(GoodParam)

	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.Ok(c, map[string]interface{}{"value": info, "total": total}, "Ok")
}

func AddOrder(c *gin.Context) { //添加订单信息
	err, info := models.AddOrd(c)
	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.Ok(c, info, "OK")
}

func UpdateOrder(c *gin.Context) { //更新订单信息
	err, info := models.UpdateOrd(c)
	if err != nil {
		app.Error(c, e.ERROR, err, err.Error())
		return
	}
	app.Ok(c, info, "OK")
}

func DeleteOrder(c *gin.Context) { //删除订单信息
	err := models.DelOrd(c)
	if err != nil {
		app.Error(c, e.ERROR, err, "删除失败")
		return
	}
	app.Ok(c, "删除成功", "OK")
}
